**************************************************
* This program performs the main empirical tests * 
* on the probability of making an M&A bid        * 
* reported in Table 5 and robustness tables      *
**************************************************

	use "C:\cow\comp_ma.dta",clear

	*Convert strings to numerics
	destring gvkey, gen(firm)	
	encode state, gen(lstateFE)
	encode incorp, gen(istateFE)
	encode port, gen(ffFE)

	*Set timeframe 
	drop if fyear < 1996

	*Drop if missing industry
	rename sic sic4
	gen sic3 = floor(sic4/10)
	gen sic1 = floor(sic4/1000)
	drop if missing(sic4)
	*Drop utilities
	drop if sic4 >= 4900 & sic4 <= 4999
	*Drop financials
	drop if sic4 >= 6000 & sic4 <= 6999
	*Drop public administration/non-classifiable firms
	drop if sic4 >= 9000 & sic4 <= 9999

	*Drop if missing headquarter state
	drop if missing(state)
	*Drop if missing state of incorporation
	drop if missing(incorp)
	*Drop if not incorporated in U.S. state
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")

	

	local statelist "DE OK MO KS TX NV NJ MD WA"
	gen treatment = 0
	foreach state of local statelist {
			replace treatment = 1 if incorp == "`state'"
	}

	*Create macros for date when law was passed
		local DE_cow = date("01Jul2000","DMY")
		local OK_cow = date("01Nov2001","DMY")
		local MO_cow = date("01Oct2003","DMY")
		local KS_cow = date("01Jan2005","DMY")
		local TX_cow = date("01Jan2006","DMY")
		local NV_cow = date("01Oct2007","DMY")
		local NJ_cow = date("11Mar2011","DMY")
		local MD_cow = date("01Oct2014","DMY")
		local WA_cow = date("01Jan2016","DMY")
		
		* adjust calendar year of fyeendt to be next year if fyenddt month < cow law date
		gen ayear = year(datadate)
		local statelist "DE OK MO KS TX NV NJ MD WA"
		foreach state of local statelist {
				replace ayear = year(datadate)-1 if incorp == "`state'" & month(datadate) < month(``state'_cow')
				}

		*cow: indicator equal to one if firm is incorporated in a state that has passed a COW law
		gen cow = 0
		local statelist "DE OK MO KS TX NV NJ MD WA"
		foreach state of local statelist {
				replace cow = 1 if incorp == "`state'" & ayear >= year(``state'_cow')
				}
				
		local indep "mveq_rd mktcap assets assetsm lvm lvb mb leverage q illiq roa"
		foreach v of local indep {
			replace `v'=0 if missing(`v')
					gen ln_`v' = log(1+`v')

		}				
		
*********************************
* Table 5 Panel A Summary stats *
*********************************

		distinct cusip
		winsor2 mveq_rd leverage q illiq roa l_bidcount l_dealvalue, replace cuts(1 99) trim
		estpost tabstat bid ceoownership cow mveq_rd leverage q illiq roa bid l_bidcount l_dealvalue, statistics (n mean sd p25 p50 p75) columns(statistics)

	
*******************************
* Table 5 Panel B Regressions *
*******************************

		reghdfe bid cow , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_bidcount cow , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_dealvalue cow , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)

		reghdfe bid cow ln_mveq_rd leverage mb illiq roa , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_bidcount cow ln_mveq_rd leverage mb illiq roa, absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_dealvalue cow ln_mveq_rd leverage mb illiq roa, absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)

		

		
		
		
		
		
*======================================*
*           ROBUSTNESS TESTS	       *
*======================================*

		* noncompete index		
		gen nceindex=0
		replace nceindex=5 if incorp=="AL"
		replace nceindex=3 if incorp=="AK"
		replace nceindex=3 if incorp=="AZ"
		replace nceindex=5 if incorp=="AR"
		replace nceindex=0 if incorp=="CA"
		replace nceindex=1 if incorp=="CO"
		replace nceindex=2 if incorp=="CO" & fyear>=1992 
		replace nceindex=3 if incorp=="CO" & fyear>=2012 
		replace nceindex=4 if incorp=="CT"
		replace nceindex=3 if incorp=="CT" & fyear>=1992
		replace nceindex=6 if incorp=="DE"
		replace nceindex=7 if incorp=="DC"
		replace nceindex=7 if incorp=="FL"
		replace nceindex=9 if incorp=="FL" & fyear>=1997
		replace nceindex=5 if incorp=="GA"
		replace nceindex=6 if incorp=="GA" & fyear>=2005
		replace nceindex=7 if incorp=="GA" & fyear>=2011
		replace nceindex=3 if incorp=="HI"
		replace nceindex=4 if incorp=="HI" & fyear>=2007
		replace nceindex=5 if incorp=="ID"
		replace nceindex=6 if incorp=="ID" & fyear>=1992
		replace nceindex=7 if incorp=="ID" & fyear>=2009
		replace nceindex=5 if incorp=="IL"
		replace nceindex=6 if incorp=="IL" & (2012<=fyear<=2013) 
		replace nceindex=5 if incorp=="IN"
		replace nceindex=6 if incorp=="IA"
		replace nceindex=6 if incorp=="KS"
		replace nceindex=7 if incorp=="KS" & fyear>=2008
		replace nceindex=6 if incorp=="KY"
		replace nceindex=5 if incorp=="KY" & fyear>=2015
		replace nceindex=2 if incorp=="LA" & fyear<=1991
		replace nceindex=4 if incorp=="LA" & (1992<=fyear<=2001)
		replace nceindex=4 if incorp=="LA" & (2004<=fyear)
		replace nceindex=4 if incorp=="ME"
		replace nceindex=5 if incorp=="MD"
		replace nceindex=6 if incorp=="MA"
		replace nceindex=5 if incorp=="MI"
		replace nceindex=5 if incorp=="MN"
		replace nceindex=4 if incorp=="MS"
		replace nceindex=5 if incorp=="MS" & fyear>=2009
		replace nceindex=7 if incorp=="MO"
		replace nceindex=2 if incorp=="MT"
		replace nceindex=4 if incorp=="NE"
		replace nceindex=5 if incorp=="NV"
		replace nceindex=2 if incorp=="NH"
		replace nceindex=1 if incorp=="NH" & fyear>=2013
		replace nceindex=4 if incorp=="NJ"
		replace nceindex=2 if incorp=="NM"
		replace nceindex=3 if incorp=="NY"
		replace nceindex=4 if incorp=="NC"
		replace nceindex=0 if incorp=="ND"
		replace nceindex=4 if incorp=="OH"
		replace nceindex=5 if incorp=="OH" & fyear>=1992
		replace nceindex=6 if incorp=="OH" & fyear>=2005
		replace nceindex=1 if incorp=="OK"
		replace nceindex=6 if incorp=="OR"
		replace nceindex=5 if incorp=="OR" & fyear>=2008
		replace nceindex=6 if incorp=="PA"
		replace nceindex=3 if incorp=="RI"
		replace nceindex=5 if incorp=="SC"
		replace nceindex=4 if incorp=="SC" & fyear>=2011
		replace nceindex=5 if incorp=="SD"
		replace nceindex=7 if incorp=="TN"
		replace nceindex=5 if incorp=="TX"
		replace nceindex=3 if incorp=="TX" & fyear>=1995
		replace nceindex=4 if incorp=="TX" & fyear>=2011
		replace nceindex=6 if incorp=="UT"
		replace nceindex=5 if incorp=="VT"
		replace nceindex=6 if incorp=="VT" & fyear>=2006
		replace nceindex=4 if incorp=="VA" & (1980<=fyear<=1991)
		replace nceindex=3 if incorp=="VA" & (1992<=fyear<=2005)
		replace nceindex=4 if incorp=="VA" & (2006<=fyear<=2013)
		replace nceindex=5 if incorp=="VA" & (2014<=fyear)
		replace nceindex=5 if incorp=="WA"
		replace nceindex=2 if incorp=="WV" 
		replace nceindex=3 if incorp=="WV" & (1984<=fyear<=1991)
		replace nceindex=3 if incorp=="WI"
		replace nceindex=4 if incorp=="WI" & fyear>=2010
		replace nceindex=5 if incorp=="WI" & fyear>=2016
		replace nceindex=4 if incorp=="WY"

		* universal demand law
		gen ud=0
		replace ud=1 if incorp=="UT" & fyear>=1992
		replace ud=1 if incorp=="NH" & fyear>=1993
		replace ud=1 if incorp=="MS" & fyear>=1993
		replace ud=1 if incorp=="NC" & fyear>=1995
		replace ud=1 if incorp=="AZ" & fyear>=1996
		replace ud=1 if incorp=="NE" & fyear>=1996
		replace ud=1 if incorp=="CT" & fyear>=1997
		replace ud=1 if incorp=="ME" & fyear>=1997
		replace ud=1 if incorp=="PA" & fyear>=1997
		replace ud=1 if incorp=="TX" & fyear>=1997
		replace ud=1 if incorp=="WY" & fyear>=1997
		replace ud=1 if incorp=="ID" & fyear>=1998
		replace ud=1 if incorp=="HI" & fyear>=2001
		replace ud=1 if incorp=="IA" & fyear>=2003
		replace ud=1 if incorp=="MA" & fyear>=2004
		replace ud=1 if incorp=="RI" & fyear>=2005
		replace ud=1 if incorp=="SD" & fyear>=2005
		
		* The five most common types of antitakeover laws adopted by states since 1982. The law types are: control share acquisition laws (CS), business combination laws (BC), fair price laws (FP), directors' duties laws (DD), and poison pill laws (PP)
 
		* cs law
		gen cs=0
		replace cs =1 if incorp=="AZ" & fyear>=1987
		replace cs =1 if incorp=="FL" & fyear>=1987
		replace cs =1 if incorp=="HI" & fyear>=1985
		replace cs =1 if incorp=="ID" & fyear>=1988
		replace cs =1 if incorp=="IN" & fyear>=1986
		replace cs =1 if incorp=="KS" & fyear>=1988
		replace cs =1 if incorp=="LA" & fyear>=1987
		replace cs =1 if incorp=="MD" & fyear>=1989
		replace cs =1 if incorp=="MA" & fyear>=1987
		replace cs =1 if incorp=="MI" & fyear>=1988
		replace cs =1 if incorp=="MN" & fyear>=1984
		replace cs =1 if incorp=="MS" & fyear>=1990
		replace cs =1 if incorp=="MO" & fyear>=1984
		replace cs =1 if incorp=="NE" & fyear>=1988
		replace cs =1 if incorp=="NV" & fyear>=1987
		replace cs =1 if incorp=="NC" & fyear>=1987
		replace cs =1 if incorp=="OH" & fyear>=1982
		replace cs =1 if incorp=="OK" & fyear>=1987
		replace cs =1 if incorp=="OR" & fyear>=1987
		replace cs =1 if incorp=="PA" & fyear>=1990
		replace cs =1 if incorp=="SC" & fyear>=1988
		replace cs =1 if incorp=="SD" & fyear>=1990
		replace cs =1 if incorp=="TN" & fyear>=1988
		replace cs =1 if incorp=="UT" & fyear>=1987
		replace cs =1 if incorp=="VA" & fyear>=1989
		replace cs =1 if incorp=="WI" & fyear>=1984
		replace cs =1 if incorp=="WY" & fyear>=1990

		* bc law
		gen bc=0
		replace bc =1 if incorp=="AZ" & fyear>=1987
		replace bc =1 if incorp=="CT" & fyear>=1988
		replace bc =1 if incorp=="DE" & fyear>=1988
		replace bc =1 if incorp=="GA" & fyear>=1988
		replace bc =1 if incorp=="ID" & fyear>=1988
		replace bc =1 if incorp=="IL" & fyear>=1989
		replace bc =1 if incorp=="IN" & fyear>=1986
		replace bc =1 if incorp=="IA" & fyear>=1997
		replace bc =1 if incorp=="KS" & fyear>=1989
		replace bc =1 if incorp=="KY" & fyear>=1986
		replace bc =1 if incorp=="ME" & fyear>=1988
		replace bc =1 if incorp=="MD" & fyear>=1989
		replace bc =1 if incorp=="MA" & fyear>=1989
		replace bc =1 if incorp=="MI" & fyear>=1989
		replace bc =1 if incorp=="MN" & fyear>=1987
		replace bc =1 if incorp=="MO" & fyear>=1986
		replace bc =1 if incorp=="NE" & fyear>=1988
		replace bc =1 if incorp=="NV" & fyear>=1991
		replace bc =1 if incorp=="NJ" & fyear>=1986
		replace bc =1 if incorp=="NY" & fyear>=1985
		replace bc =1 if incorp=="OH" & fyear>=1990
		replace bc =1 if incorp=="OK" & fyear>=1991
		replace bc =1 if incorp=="OR" & fyear>=1991
		replace bc =1 if incorp=="PA" & fyear>=1988
		replace bc =1 if incorp=="RI" & fyear>=1990
		replace bc =1 if incorp=="SC" & fyear>=1988
		replace bc =1 if incorp=="SD" & fyear>=1990
		replace bc =1 if incorp=="TN" & fyear>=1988
		replace bc =1 if incorp=="TX" & fyear>=1997
		replace bc =1 if incorp=="VA" & fyear>=1988
		replace bc =1 if incorp=="WA" & fyear>=1987
		replace bc =1 if incorp=="WI" & fyear>=1987
		replace bc =1 if incorp=="WY" & fyear>=1989

		* fp law
		gen fp=0
		replace fp =1 if incorp=="AZ" & fyear>=1987
		replace fp =1 if incorp=="CT" & fyear>=1984
		replace fp =1 if incorp=="FL" & fyear>=1987
		replace fp =1 if incorp=="GA" & fyear>=1985
		replace fp =1 if incorp=="ID" & fyear>=1988
		replace fp =1 if incorp=="IL" & fyear>=1985
		replace fp =1 if incorp=="IN" & fyear>=1986
		replace fp =1 if incorp=="KY" & fyear>=1984
		replace fp =1 if incorp=="LA" & fyear>=1984
		replace fp =1 if incorp=="MD" & fyear>=1983
		replace fp =1 if incorp=="MI" & fyear>=1984
		replace fp =1 if incorp=="MN" & fyear>=1991
		replace fp =1 if incorp=="MS" & fyear>=1985
		replace fp =1 if incorp=="MO" & fyear>=1986
		replace fp =1 if incorp=="NV" & fyear>=1991
		replace fp =1 if incorp=="NJ" & fyear>=1986
		replace fp =1 if incorp=="NY" & fyear>=1985
		replace fp =1 if incorp=="NC" & fyear>=1987
		replace fp =1 if incorp=="OH" & fyear>=1990
		replace fp =1 if incorp=="PA" & fyear>=1988
		replace fp =1 if incorp=="RI" & fyear>=1990
		replace fp =1 if incorp=="SC" & fyear>=1988
		replace fp =1 if incorp=="SD" & fyear>=1990
		replace fp =1 if incorp=="TN" & fyear>=1988
		replace fp =1 if incorp=="VA" & fyear>=1985
		replace fp =1 if incorp=="WA" & fyear>=1985
		replace fp =1 if incorp=="WI" & fyear>=1984

		* dd law
		gen dd=0
		replace dd =1 if incorp=="AZ" & fyear>=1987
		replace dd =1 if incorp=="CT" & fyear>=1988
		replace dd =1 if incorp=="FL" & fyear>=1989
		replace dd =1 if incorp=="GA" & fyear>=1989
		replace dd =1 if incorp=="HI" & fyear>=1989
		replace dd =1 if incorp=="ID" & fyear>=1988
		replace dd =1 if incorp=="IL" & fyear>=1985
		replace dd =1 if incorp=="IN" & fyear>=1986
		replace dd =1 if incorp=="IA" & fyear>=1989
		replace dd =1 if incorp=="KY" & fyear>=1988
		replace dd =1 if incorp=="LA" & fyear>=1988
		replace dd =1 if incorp=="ME" & fyear>=1985
		replace dd =1 if incorp=="MD" & fyear>=1999
		replace dd =1 if incorp=="MA" & fyear>=1989
		replace dd =1 if incorp=="MN" & fyear>=1987
		replace dd =1 if incorp=="MS" & fyear>=1990
		replace dd =1 if incorp=="MO" & fyear>=1986
		replace dd =1 if incorp=="NE" & fyear>=1988
		replace dd =1 if incorp=="NV" & fyear>=1991
		replace dd =1 if incorp=="NJ" & fyear>=1989
		replace dd =1 if incorp=="NM" & fyear>=1987
		replace dd =1 if incorp=="NY" & fyear>=1987
		replace dd =1 if incorp=="NC" & fyear>=1993
		replace dd =1 if incorp=="ND" & fyear>=1993
		replace dd =1 if incorp=="OH" & fyear>=1984
		replace dd =1 if incorp=="OR" & fyear>=1989
		replace dd =1 if incorp=="PA" & fyear>=1990
		replace dd =1 if incorp=="RI" & fyear>=1990
		replace dd =1 if incorp=="SD" & fyear>=1990
		replace dd =1 if incorp=="TN" & fyear>=1988
		replace dd =1 if incorp=="TX" & fyear>=2003
		replace dd =1 if incorp=="VT" & fyear>=1998
		replace dd =1 if incorp=="VA" & fyear>=1988
		replace dd =1 if incorp=="WI" & fyear>=1987
		replace dd =1 if incorp=="WY" & fyear>=1990

		* pp law
		gen pp=0
		replace pp =1 if incorp=="CO" & fyear>=1989
		replace pp =1 if incorp=="CT" & fyear>=2003
		replace pp =1 if incorp=="FL" & fyear>=1989
		replace pp =1 if incorp=="GA" & fyear>=1988
		replace pp =1 if incorp=="HI" & fyear>=1988
		replace pp =1 if incorp=="ID" & fyear>=1988
		replace pp =1 if incorp=="IL" & fyear>=1989
		replace pp =1 if incorp=="IN" & fyear>=1986
		replace pp =1 if incorp=="IA" & fyear>=1989
		replace pp =1 if incorp=="KY" & fyear>=1988
		replace pp =1 if incorp=="ME" & fyear>=2002
		replace pp =1 if incorp=="MD" & fyear>=1999
		replace pp =1 if incorp=="MA" & fyear>=1989
		replace pp =1 if incorp=="MI" & fyear>=2001
		replace pp =1 if incorp=="MN" & fyear>=1995
		replace pp =1 if incorp=="MS" & fyear>=2005
		replace pp =1 if incorp=="MO" & fyear>=1999
		replace pp =1 if incorp=="NV" & fyear>=1989
		replace pp =1 if incorp=="NJ" & fyear>=1989
		replace pp =1 if incorp=="NY" & fyear>=1988
		replace pp =1 if incorp=="NC" & fyear>=1989
		replace pp =1 if incorp=="OH" & fyear>=1986
		replace pp =1 if incorp=="OR" & fyear>=1989
		replace pp =1 if incorp=="PA" & fyear>=1988
		replace pp =1 if incorp=="RI" & fyear>=1990
		replace pp =1 if incorp=="SC" & fyear>=1998
		replace pp =1 if incorp=="SD" & fyear>=1990
		replace pp =1 if incorp=="TN" & fyear>=1989
		replace pp =1 if incorp=="TX" & fyear>=2003
		replace pp =1 if incorp=="UT" & fyear>=1989
		replace pp =1 if incorp=="VT" & fyear>=2008
		replace pp =1 if incorp=="VA" & fyear>=1990
		replace pp =1 if incorp=="WA" & fyear>=1998
		replace pp =1 if incorp=="WI" & fyear>=1987
		replace pp =1 if incorp=="WY" & fyear>=2009

		* Revlon case
		gen revlon=0
		replace revlon =1 if incorp=="CA" & fyear>=2002
		replace revlon =1 if incorp=="DE" & fyear>=1986
		replace revlon =1 if incorp=="IL" & fyear>=1988
		replace revlon =1 if incorp=="IN" & fyear>=1987
		replace revlon =-1 if incorp=="IN" & fyear>=2001
		replace revlon =1 if incorp=="KS" & fyear>=2003
		replace revlon =-1 if incorp=="MD" & fyear>=2004
		replace revlon =1 if incorp=="MD" & fyear>=2009
		replace revlon =1 if incorp=="MI" & fyear>=1986
		replace revlon =1 if incorp=="MN" & fyear>=1987
		replace revlon =1 if incorp=="MO" & fyear>=1999
		replace revlon =1 if incorp=="NV" & fyear>=1997
		replace revlon =-1 if incorp=="NV" & fyear>=1999
		replace revlon =1 if incorp=="NH" & fyear>=2001
		replace revlon =1 if incorp=="NY" & fyear>=1986
		replace revlon =-1 if incorp=="NY" & fyear>=1997
		replace revlon =-1 if incorp=="NC" & fyear>=2001
		replace revlon =-1 if incorp=="OH" & fyear>=1990
		replace revlon =-1 if incorp=="PA" & fyear>=1987
		replace revlon =-1 if incorp=="VA" & fyear>=1999
		replace revlon =-1 if incorp=="WI" & fyear>=1999
		
		* Unocal case
		gen unocal=0
		replace unocal =1 if incorp=="AR" & fyear>=1993
		replace unocal =1 if incorp=="CA" & fyear>=1989
		replace unocal =1 if incorp=="DE" & fyear>=1985
		replace unocal =1 if incorp=="CA" & fyear>=2002
		replace unocal =1 if incorp=="FL" & fyear>=1989
		replace unocal =1 if incorp=="IL" & fyear>=1988
		replace unocal =1 if incorp=="IN" & fyear>=1987
		replace unocal =-1 if incorp=="IN" & fyear>=2001
		replace unocal =1 if incorp=="KS" & fyear>=2003
		replace unocal =-1 if incorp=="MD" & fyear>=1988
		replace unocal =1 if incorp=="MD" & fyear>=2004
		replace unocal =-1 if incorp=="MA" & fyear>=2003
		replace unocal =1 if incorp=="MI" & fyear>=1986
		replace unocal =1 if incorp=="MN" & fyear>=1987
		replace unocal =1 if incorp=="MO" & fyear>=1999
		replace unocal =-1 if incorp=="NV" & fyear>=1985
		replace unocal =-1 if incorp=="NJ" & fyear>=1998
		replace unocal =-1 if incorp=="NY" & fyear>=1986
		replace unocal =-1 if incorp=="NC" & fyear>=2001
		replace unocal =-1 if incorp=="OH" & fyear>=1986
		replace unocal =-1 if incorp=="PA" & fyear>=1986
		replace unocal =1 if incorp=="TX" & fyear>=1989
		replace unocal =-1 if incorp=="VA" & fyear>=1995
		replace unocal =1 if incorp=="WI" & fyear>=1989

		* Blasius case
		gen blasius=0
		replace blasius =1 if incorp=="CT" & fyear>=2000
		replace blasius =1 if incorp=="DE" & fyear>=1988
		replace blasius =-1 if incorp=="GA" & fyear>=1997
		replace blasius =-1 if incorp=="IN" & fyear>=1993
		replace blasius =-1 if incorp=="IN" & fyear>=2001
		replace blasius =1 if incorp=="KS" & fyear>=2003
		replace blasius =-1 if incorp=="MD" & fyear>=1999
		replace blasius =1 if incorp=="MD" & fyear>=2005
		replace blasius =1 if incorp=="MA" & fyear>=1990
		replace blasius =1 if incorp=="MI" & fyear>=2003
		replace blasius =1 if incorp=="NV" & fyear>=1997
		replace blasius =-1 if incorp=="NV" & fyear>=1999
		replace blasius =-1 if incorp=="NJ" & fyear>=1998
		replace blasius =-1 if incorp=="NC" & fyear>=1984
		replace blasius =-1 if incorp=="OH" & fyear>=1986
		replace blasius =-1 if incorp=="PA" & fyear>=1990
		replace blasius =-1 if incorp=="VA" & fyear>=1986
		
		* Madaroty classified board law
		gen mcb=0
		replace mcb =1 if incorp=="IN" & fyear>=2009
		replace mcb =1 if incorp=="IA" & fyear>=2011
		replace mcb =-1 if incorp=="IA" & fyear>=2014
		replace mcb =1 if incorp=="MA" & fyear>=1990
		replace mcb =1 if incorp=="OK" & fyear>=2010
		replace mcb =-1 if incorp=="OK" & fyear>=2013
		
		
		
		
********************************
* Table 7 Managerial ownership *
********************************

		reghdfe bid cow##c.ceoownership ln_mveq_rd leverage mb illiq roa , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_bidcount cow##c.ceoownership ln_mveq_rd leverage mb illiq roa, absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_dealvalue cow##c.ceoownership ln_mveq_rd leverage mb illiq roa, absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)

		
*********************************
* Table 8 Independent directors *
*********************************

		reghdfe bid cow##c.pct_inddir ln_mveq_rd leverage mb illiq roa , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_bidcount cow##c.pct_inddir ln_mveq_rd leverage mb illiq roa, absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_dealvalue cow##c.pct_inddir ln_mveq_rd leverage mb illiq roa, absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)

		
************************************
* Table 10 HQ state = Incorp state *
************************************

		reghdfe bid cow  if state==incorp , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_bidcount cow if state==incorp, absorb(firm lstate#fyear sic2#fyear) vce(cluster istate)
		reghdfe l_dealvalue cow  if state==incorp, absorb(firm lstate#fyear sic2#fyear) vce(cluster istate)
		

**************************	
* Table 11 Drop DE firms *
**************************	

		reghdfe bid cow ln_mveq_rd leverage mb illiq roa if state~="DE" , absorb(firm lstate#fyear sic2#fyear) vce(cluster istate)
		reghdfe l_bidcount cow ln_mveq_rd leverage mb illiq roa if state~="DE", absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_dealvalue cow ln_mveq_rd leverage mb illiq roa if state~="DE", absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)

		
*************************************
* Table 12 Additional firm controls *
*************************************

		local control "cbdefml ceoownership div busseg activeownership5 activeownership cown_mean "
		foreach v of local control {
		replace `v'=0 if missing(`v') 
		}

		reghdfe bid cow cbdefml ceoownership activeownership5 div busseg cown_mean ln_mveq_rd leverage mb illiq roa , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_bidcount cow cbdefml ceoownership activeownership5 div busseg cown_mean ln_mveq_rd leverage mb illiq roa, absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_dealvalue cow cbdefml ceoownership activeownership5 div busseg cown_mean ln_mveq_rd leverage mb illiq roa, absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)

		* lagged controls

		xtset firm fyear
	
		reghdfe bid cow ln_mveq_rd leverage mb illiq roa cbdefml ceoownership activeownership5 div busseg cown_mean , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)

		local lagvar "ln_mveq_rd leverage mb illiq roa cbdefml ceoownership activeownership5 div busseg cown_mean"
		foreach v of local lagvar {
			gen lag_`v' = l.`v'
			replace lag_`v'=`v' if missing(lag_`v')	
		}				
		reghdfe bid cow ln_mveq_rd lag_leverage lag_mb lag_illiq lag_roa lag_cbdefml lag_ceoownership lag_activeownership5 lag_div lag_busseg lag_cown_mean , absorb(firm lstate#fyear lstate#sic2) vce(cluster istate)
		
		
**************************************
* Table 13 Additional legal controls *
**************************************

		reghdfe bid cow nceindex ud mcb cs bc fp dd pp revlon unocal blasius, absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_bidcount cow nceindex ud mcb cs bc fp dd pp revlon unocal blasius, absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_dealvalue cow nceindex ud mcb cs bc fp dd pp revlon unocal blasius, absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)


*******************************************	
* Table 14 High dimensional fixed effects *
*******************************************	

		reghdfe bid cow , absorb(firm lstate#sic2#fyear) vce(cluster istate)
		reghdfe l_bidcount cow , absorb(firm lstate#sic2#fyear) vce(cluster istate)
		reghdfe l_dealvalue cow , absorb(firm lstate#sic2#fyear) vce(cluster istate)

		
************************
* Table 15 Matched DiD *
************************
		
		local control "ceoownership div busseg activeownership5 activeownership cown_mean "
		foreach v of local control {
		replace `v'=0 if missing(`v') 
		}

		psmatch2 treatment ln_mveq_rd leverage_mkt roa cbdefml ceoownership activeownership5 div busseg cown_mean i.lstateFE i.fyear i.sic2, n(1)		
		bys permno: egen matching_sample = sum(_weight)
		reghdfe bid cow if matching_sample!=0 , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_bidcount cow if matching_sample!=0 , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_dealvalue cow if matching_sample!=0 , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)

		
************************
* Table 16 Stacked DiD *
************************

		expand 2, gen(event_DE)
		drop if event_DE==1 & treatment==1 & incorp~="DE" 
		drop if event_DE==1 & (ayear<1996 | ayear>2004)

		expand 2 if event_DE==0, gen(event_OK)
		drop if event_OK==1 & treatment==1 & incorp~="OK"
		drop if event_OK==1 & (ayear<1997 | ayear>2005)

		expand 2 if event_DE==0 & event_OK==0, gen(event_MO)
		drop if event_MO==1 & treatment==1 & incorp~="MO"
		drop if event_MO==1 & (ayear<1999 | ayear>2007)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0, gen(event_KS)
		drop if event_KS==1 & treatment==1 & incorp~="KS"
		drop if event_KS==1 & (ayear<2001 | ayear>2009)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0, gen(event_TX)
		drop if event_TX==1 & treatment==1 & incorp~="TX"
		drop if event_TX==1 & (ayear<2002 | ayear>2010)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0, gen(event_NV)
		drop if event_NV==1 & treatment==1 & incorp~="NV"
		drop if event_NV==1 & (ayear<2003 | ayear>2011)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0 & event_NV==0, gen(event_NJ)
		drop if event_NJ==1 & treatment==1 & incorp~="NJ"
		drop if event_NJ==1 & (ayear<2007 | ayear>2015)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0 & event_NV==0 & event_NJ==0, gen(event_MD)
		drop if event_MD==1 & treatment==1 & incorp~="MD"
		drop if event_MD==1 & (ayear<2010 | ayear>2018) 
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0 & event_NV==0 & event_NJ==0 & event_MD==0, gen(event_WA)
		drop if event_WA==1 & treatment==1 & incorp~="WA"
		drop if event_WA==1 & (ayear<2012 | ayear>2020)
		
		drop if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0 & event_NV==0 & event_NJ==0 & event_MD==0 & event_WA==0
		
		reghdfe bid cow, absorb(firm lstate sic3 fyear) vce(cluster istate)
		reghdfe l_bidcount cow, absorb(firm lstate sic3 fyear) vce(cluster istate)
		reghdfe l_dealvalue cow, absorb(firm lstate sic1#fyear) vce(cluster istate)
		
		

********************************
* Table B3 Dynamic coeff trend *
********************************

	use "C:\cow\comp_ma.dta",clear

	*Convert strings to numerics
	destring gvkey, gen(firm)	
	encode state, gen(lstateFE)
	encode incorp, gen(istateFE)
	encode port, gen(ffFE)

	*Set timeframe 
	drop if fyear < 1996

	*Drop if missing industry
	rename sic sic4
	gen sic3 = floor(sic4/10)
	gen sic1 = floor(sic4/1000)
	drop if missing(sic4)
	*Drop utilities
	drop if sic4 >= 4900 & sic4 <= 4999
	*Drop financials
	drop if sic4 >= 6000 & sic4 <= 6999
	*Drop public administration/non-classifiable firms
	drop if sic4 >= 9000 & sic4 <= 9999

	*Drop if missing headquarter state
	drop if missing(state)
	*Drop if missing state of incorporation
	drop if missing(incorp)
	*Drop if not incorporated in U.S. state
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")

	

	local statelist "DE OK MO KS TX NV NJ MD WA"
	gen treatment = 0
	foreach state of local statelist {
			replace treatment = 1 if incorp == "`state'"
	}

	*Create macros for date when law was passed
		local DE_cow = date("01Jul2000","DMY")
		local OK_cow = date("01Nov2001","DMY")
		local MO_cow = date("01Oct2003","DMY")
		local KS_cow = date("01Jan2005","DMY")
		local TX_cow = date("01Jan2006","DMY")
		local NV_cow = date("01Oct2007","DMY")
		local NJ_cow = date("11Mar2011","DMY")
		local MD_cow = date("01Oct2014","DMY")
		local WA_cow = date("01Jan2016","DMY")
		
		* adjust calendar year of fyeendt to be next year if fyenddt month < cow law date
		gen ayear = year(datadate)
		local statelist "DE OK MO KS TX NV NJ MD WA"
		foreach state of local statelist {
				replace ayear = year(datadate)-1 if incorp == "`state'" & month(datadate) < month(``state'_cow')
				}

		*cow: indicator equal to one if firm is incorporated in a state that has passed a COW law
		gen cow = 0
		local statelist "DE OK MO KS TX NV NJ MD WA"
		foreach state of local statelist {
				replace cow = 1 if incorp == "`state'" & ayear >= year(``state'_cow')
				}
				
		local indep "mveq_rd mktcap assets assetsm lvm lvb mb leverage q illiq roa"
		foreach v of local indep {
			replace `v'=0 if missing(`v')
					gen ln_`v' = log(1+`v')

		}				

		*Initialize variables
		forval x=1/25 {
			gen cown`x'=0
			}

		forval x=0/25 {
			gen cow`x'=0
			}


		gen cow2p = 0
		gen cow3p = 0
		gen cow4p = 0

		*Generate event time index
		gen indexyear=0
		foreach state of local statelist {
			forval x=-25(1)25 {
			replace indexyear=`x' if incorp == "`state'" & ayear == year(``state'_cow')+`x'
			}
			}	
		
		*Generate event time dummies
		foreach state of local statelist {
			forval x=1/25 {
			replace cown`x' = 1 if incorp == "`state'" & ayear == year(``state'_cow')-`x'
			}
			}	
			
		foreach state of local statelist {
			forval x=0/25 {
			replace cow`x' = 1 if incorp == "`state'" & ayear == year(``state'_cow')+`x'
			}
			}
			
		foreach state of local statelist {
			replace cow2p = 1 if incorp == "`state'" & ayear >= year(``state'_cow')+2
			replace cow3p = 1 if incorp == "`state'" & ayear >= year(``state'_cow')+3
			replace cow4p = 1 if incorp == "`state'" & ayear >= year(``state'_cow')+4
			}

		reghdfe bid cown2 cown1 cow0 cow1 cow2 cow3p , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_bidcount cown2 cown1 cow0 cow1 cow2 cow3p , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		reghdfe l_dealvalue cown2 cown1 cow0 cow1 cow2 cow3p , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)


		
*******************************
* Figure B2 Block permutation *
*******************************

	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\comp_ma.dta"
	set more off

	*Convert strings to numerics
	destring gvkey, gen(firm)	
	encode state, gen(lstateFE)
	encode incorp, gen(istateFE)
	encode port, gen(ffFE)

	*Set timeframe 
	drop if fyear < 1996 

	*Drop if missing industry
	rename sic sic4
	gen sic3 = floor(sic4/10)
	gen sic1 = floor(sic4/1000)
	drop if missing(sic4)
	*Drop utilities
	drop if sic4 >= 4900 & sic4 <= 4999
	*Drop financials
	drop if sic4 >= 6000 & sic4 <= 6999
	*Drop public administration/non-classifiable firms
	drop if sic4 >= 9000 & sic4 <= 9990


	*Drop if missing headquarter state
	drop if missing(state)
	*Drop if missing state of incorporation
	drop if missing(incorp)
	*Drop if not incorporated in U.S. state
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")


	* Loop 1000;
		forval y= 1/1000 {
		bysort incorp_no: gen ryear_`y' = runiformint(1996,2018)
		bysort incorp_no: replace ryear_`y' = ryear_`y'[1]
		bysort incorp_no: gen treatment_`y' = runiformint(0,1)
		bysort incorp_no: replace treatment_`y' = treatment_`y'[1]
		gen cow_`y' =0
		replace cow_`y' =1 if treatment_`y'==1 & fyear >= ryear_`y'
	
		quietly reghdfe bid cow_`y' , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		estimate store m`y'
		drop ryear_`y' treatment_`y' cow_`y'  
		}

		estout m* using "bid_loop1.csv", cells(b) replace
		
		
	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\comp_ma.dta"
	set more off

	*Convert strings to numerics
	destring gvkey, gen(firm)	
	encode state, gen(lstateFE)
	encode incorp, gen(istateFE)
	encode port, gen(ffFE)

	*Set timeframe 
	drop if fyear < 1996 

	*Drop if missing industry
	rename sic sic4
	gen sic3 = floor(sic4/10)
	gen sic1 = floor(sic4/1000)
	drop if missing(sic4)
	*Drop utilities
	drop if sic4 >= 4900 & sic4 <= 4999
	*Drop financials
	drop if sic4 >= 6000 & sic4 <= 6999
	*Drop public administration/non-classifiable firms
	drop if sic4 >= 9000 & sic4 <= 9990


	*Drop if missing headquarter state
	drop if missing(state)
	*Drop if missing state of incorporation
	drop if missing(incorp)
	*Drop if not incorporated in U.S. state
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")


	* Loop 1000;
		forval y= 1/1000 {
		bysort incorp_no: gen ryear_`y' = runiformint(1996,2018)
		bysort incorp_no: replace ryear_`y' = ryear_`y'[1]
		bysort incorp_no: gen treatment_`y' = runiformint(0,1)
		bysort incorp_no: replace treatment_`y' = treatment_`y'[1]
		gen cow_`y' =0
		replace cow_`y' =1 if treatment_`y'==1 & fyear >= ryear_`y'
	
		quietly reghdfe l_bidcount cow_`y' , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		estimate store m`y'
		drop ryear_`y' treatment_`y' cow_`y'  
		}

		estout m* using "bidcount_loop1.csv", cells(b) replace
				
		
		
	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\comp_ma.dta"
	set more off

	*Convert strings to numerics
	destring gvkey, gen(firm)	
	encode state, gen(lstateFE)
	encode incorp, gen(istateFE)
	encode port, gen(ffFE)

	*Set timeframe 
	drop if fyear < 1996 

	*Drop if missing industry
	rename sic sic4
	gen sic3 = floor(sic4/10)
	gen sic1 = floor(sic4/1000)
	drop if missing(sic4)
	*Drop utilities
	drop if sic4 >= 4900 & sic4 <= 4999
	*Drop financials
	drop if sic4 >= 6000 & sic4 <= 6999
	*Drop public administration/non-classifiable firms
	drop if sic4 >= 9000 & sic4 <= 9990


	*Drop if missing headquarter state
	drop if missing(state)
	*Drop if missing state of incorporation
	drop if missing(incorp)
	*Drop if not incorporated in U.S. state
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")


	* Loop 1000;
		forval y= 1/1000 {
		bysort incorp_no: gen ryear_`y' = runiformint(1996,2018)
		bysort incorp_no: replace ryear_`y' = ryear_`y'[1]
		bysort incorp_no: gen treatment_`y' = runiformint(0,1)
		bysort incorp_no: replace treatment_`y' = treatment_`y'[1]
		gen cow_`y' =0
		replace cow_`y' =1 if treatment_`y'==1 & fyear >= ryear_`y'
	
		quietly reghdfe l_dealvalue cow_`y' , absorb(firm lstate#fyear sic3#fyear) vce(cluster istate)
		estimate store m`y'
		drop ryear_`y' treatment_`y' cow_`y'  
		}

		estout m* using "bidvalue_loop1.csv", cells(b) replace
		
		
	